package protocol.SZ_2021;

import java.util.HashMap;

public class Handle2021SZ12 implements IHandle2021SZ {
    @Override
    public String handle(SZ_2021Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x06:
                return handle1206(cmd);
            case 0x09:
                return handle1204(cmd);
            case 0x10:
                return handle1210(cmd);
            case 0x11:
                return handle1211(cmd);
            case 0x12:
                return handle1212(cmd);
            default:
                return "深标:未匹配的命令字"+(cmd.readOrder()+","+cmd.readSubOrder());
        }
    }

    private String handle1212(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:文件上传完成");
        builder.append("\r\n");
        builder.append("文件名称:"+cmd.readString(cmd.readInt(1)));
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"图片");
        list.put(1,"音频");
        list.put(2,"视频");
        list.put(3,"文本");
        list.put(4,"其他");
        builder.append("文件类型:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        builder.append("文件大小:"+cmd.readDWord());
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle1211(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:附件文件信息");
        builder.append("\r\n");
        builder.append("文件名称:"+cmd.readString(cmd.readInt(1)));
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"图片");
        list.put(1,"音频");
        list.put(2,"视频");
        list.put(3,"文本");
        list.put(4,"其他");
        builder.append("文件类型:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        builder.append("文件大小:"+cmd.readDWord());
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle1210(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:报警附件信息");
        builder.append("\r\n");
        builder.append("终端 ID:"+cmd.readBCD(6));
        builder.append("\r\n");
        cmd.moveIndex(17);
        builder.append("报警编号:"+cmd.readBCD(32));
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"正常报警文件信息");
        list.put(1,"补传报警文件信息");
        builder.append("信息类型:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        int num = cmd.readInt(1);
        builder.append("附件数量:"+num);
        builder.append("\r\n");

        for (int i = 0; i < num; i++) {
            builder.append("    文件名称:"+cmd.readString(cmd.readInt(1)));
            builder.append("\r\n");
            builder.append("    文件大小:"+cmd.readDWord());
            builder.append("\r\n");
        }

        return builder.toString();
    }

    private String handle1206(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:文件上传完成通知");
        builder.append("\r\n");
        builder.append("应答流水号:"+cmd.readWord());
        builder.append("\r\n");
        builder.append("结果:"+(cmd.readInt(1) ==0?"成功":"失败"));
        builder.append("\r\n");
        return builder.toString();
    }

    private String handle1204(SZ_2021Cmd cmd) {

        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:实时音视频媒体通道注册");
        builder.append("\r\n");
        builder.append("终端ID:"+cmd.readBCD(7));
        builder.append("\r\n");
        builder.append("车牌颜色:"+cmd.readInt(1));
        builder.append("\r\n");
        builder.append("车牌:"+cmd.readString(16));
        builder.append("\r\n");
        builder.append("逻辑通道号（0代表全部）:"+cmd.readInt(1));
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"子码流");
        list.put(1,"主码流");
        builder.append("码流类型:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        list.clear();
        list.put(0,"音视频");
        list.put(1,"视频");
        list.put(2,"双向对讲");
        list.put(3,"监听");
        list.put(4,"中心广播");
        list.put(5,"透传");
        list.put(10,"GPS");
        list.put(11,"基本信息");
        list.put(12,"报警日志");
        list.put(13,"系统操作日志");
        list.put(14,"ACC信息");
        list.put(15,"CAN信息");
        list.put(16,"拨号日志");
        list.put(17,"GDS数据");
        builder.append("数据类型:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        list.clear();
        list.put(0,"音视频");
        list.put(1,"视频");
        builder.append("视频类型:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        return builder.toString();
    }
}
